package view;


import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import controler.SistemaIndumentaria;


public class AltaMaterial extends JFrame {
	private static final long serialVersionUID = 1L;
	private JLabel lblCodigo;
	private JTextField txtCodigo;
	private JLabel lblNombre;
	private JTextField txtNombre;
	private JLabel lblptoPedido;
	private JTextField txtPtopedido;
	private JLabel lblCosto;
	private JTextField txtCosto;
	private JLabel lblStock;
	private JTextField txtStock;
	private JLabel lblProveedor;
	private JTextField txtProveedor;
	private JButton btnAgregar;
	private JButton btnCerrar;
	private JLabel lblEstado;
	private JLabel txtEstado;
	
	public AltaMaterial(){
		this.setVisible(true);
		setBounds(100, 100, 450, 300);
		this.setLocationRelativeTo(null);
		this.setTitle("Agregar nuevo material");
		this.setLayout(new GridLayout(8,2));
		
		Container contenedor = this.getContentPane();
		
		lblCodigo = new JLabel();
		lblCodigo.setText("Codigo:");
		contenedor.add(lblCodigo);
		
		txtCodigo = new JTextField();
		txtCodigo.setSize(30,100);
		contenedor.add(txtCodigo);
		
		lblNombre = new JLabel();
		lblNombre.setText("Nombre:");
		contenedor.add(lblNombre);
		
		txtNombre = new JTextField();
		txtNombre.setSize(30,100);
		contenedor.add(txtNombre);
		
		lblptoPedido = new JLabel();
		lblptoPedido.setText("Punto de pedido:");
		contenedor.add(lblptoPedido);
		
		txtPtopedido = new JTextField();
		txtPtopedido.setSize(30,100);
		contenedor.add(txtPtopedido);
		
		lblCosto = new JLabel();
		lblCosto.setText("Costo:");
		contenedor.add(lblCosto);
		
		txtCosto = new JTextField();
		txtCosto.setSize(30,100);
		contenedor.add(txtCosto);
	
		lblStock = new JLabel();
		lblStock.setText("Stock:");
		contenedor.add(lblStock);
		
		txtStock = new JTextField();
		txtStock.setSize(30,100);
		contenedor.add(txtStock);
		
		lblProveedor = new JLabel();
		lblProveedor.setText("Proveedor:");
		contenedor.add(lblProveedor);
		
		txtProveedor = new JTextField();
		txtProveedor.setSize(30,100);
		contenedor.add(txtProveedor);
		
		lblEstado = new JLabel();
		lblEstado.setText("Operacion:");
		contenedor.add(lblEstado);
		
		txtEstado = new JLabel();
		contenedor.add(txtEstado);
		
		btnAgregar = new JButton();
		btnAgregar.setText("Agregar");
		btnAgregar.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {

				if((!txtCodigo.getText().equalsIgnoreCase(""))&&(!txtNombre.getText().equalsIgnoreCase(""))&&(!txtPtopedido.getText().equalsIgnoreCase(""))&&(!txtCosto.getText().equalsIgnoreCase(""))&&(!txtStock.getText().equalsIgnoreCase(""))&&(!txtProveedor.getText().equalsIgnoreCase("")))
				{
					if(SistemaIndumentaria.getInstancia().agregarMaterial(Integer.parseInt(txtCodigo.getText()),txtNombre.getText(), Integer.parseInt(txtPtopedido.getText()),Float.parseFloat(txtCosto.getText()),Integer.parseInt(txtStock.getText()),Integer.parseInt(txtProveedor.getText()))){
						txtEstado.setText("Agregado");								
					}			
					else
						txtEstado.setText("No agregado");
				}
				else{
					txtEstado.setText("Incompleto");
				
				}
			}
		});
		contenedor.add(btnAgregar);
		
		btnCerrar = new JButton();
		btnCerrar.setText("Cerrar");
		contenedor.add(btnCerrar);	
		btnCerrar.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {

				AltaMaterial.this.setVisible(false);
			}
		});
		this.pack();
		
	}
}
